<!DOCTYPE html>
<html lang="en" style="font-size: 100px;">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

       

        .box {
            width: 2rem;
            height: 1rem;
            background-color: blue;
        }


        .box1 {
            width: 100px;
            height: 100px;
            background-color: blueviolet;
        }
    </style>
</head>

<body>
    <div class="box"></div>
    <div class="box1"></div>
    <script>
        window.onresize = function () {
            var width = document.body.clientWidth
            console.log(width);
            var font = width / 10 + 'px'
            console.log(font);
            document.documentElement.style.fontSize = font
        }


        window.onload = function () {
            var width = document.body.clientWidth
            console.log(width);
            var font = width / 10 + 'px'
            console.log(font);
            document.documentElement.style.fontSize = font
        }


    </script>
</body>

</html>